/*
 * @Author: duchengdong
 * @Date: 2021-10-12 16:30:51
 * @LastEditors: duchengdong
 * @LastEditTime: 2021-12-28 21:20:26
 * @Description:
 */
import { useAppDispatch } from "../hooks";
import { deleteBook } from "../store/bookSlice";
import { useHistory } from "react-router-dom";
import { Button } from "antd";

type propTypes = {
    title: string | undefined;
    author: string | undefined;
    id: string;
}

const BookInfo = ({
    title,
    author,
    id,
    ...rest
}: propTypes) => {
    const dispatch = useAppDispatch();
    const history = useHistory();

    const redirect = (id: string) => {
        history.push(`/edit/${id}`);
    };

    return (
        <div>
            <div>
                <h4>{title}</h4>
                <p>{author}</p>
            </div>
            <div>
                <Button type="primary" onClick={() => dispatch(deleteBook({ id }))}>
                    delete Button
                </Button>
                <Button onClick={() => redirect(id)}>edit Button</Button>
            </div>
        </div>
    );
};

export default BookInfo;
